package com.biomatch.response;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.biomatch.domain.UserInfo;
import com.biomatch.dto.Pagination;
import lombok.Data;

@Data
public class RestResult<T>{

    public int code;

    private String msg;

    private UserInfo userInfo;

    private Pagination pagination = new Pagination();

    private T data;

    public RestResult<T> setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
        return this;
    }

    public UserInfo getUserInfo(){
        return userInfo;
    }

    public RestResult<T> setCode(RestCode RestCode) {
        this.code = RestCode.code;
        return this;
    }

    public int getCode() {
        return code;
    }

    public RestResult<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public RestResult<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public RestResult<T> setData(T data) {
        this.data = data;
        return this;
    }

    public RestResult<T> setPagination(IPage<T> page){
        if (page != null) {
            this.pagination.setTotal(page.getTotal());
            this.pagination.setPageSize(page.getSize());
            this.pagination.setCurrent(page.getCurrent());
            this.setData((T)page.getRecords());
            this.pagination.setTotalPage(page.getPages());
        }
        return this;
    }
}
